# 主动合约策略
from loguru import logger

limit_price = True
trade_strategy = {
    # 合约的总最大持仓量
    "max_volume": 15,
    # 开仓价差
    "open_spread": 20,
    # 开仓量，成交后相减，平仓后相加
    "open_volume": 5,
    # 平仓价差
    "close_spread": 80,
    # 平仓量，开仓成交后相加，平仓成交后相减
    "close_volume": 1,
    # 最大挂单量，单次挂单，无论盘口多少均不大于该量
    "max_order_volume": 2
}


def open_spread():
    return trade_strategy['open_spread']


def open_volume():
    return trade_strategy['open_volume']


def close_spread():
    return trade_strategy['close_spread']


def close_volume():
    return trade_strategy['close_volume']


def max_order_volume():
    return trade_strategy['max_order_volume']


def update_left_volume(volume, offset):
    trade_strategy['open_volume'] -= volume if offset == "OPEN" else -volume
    trade_strategy['close_volume'] -= volume if offset == "CLOSE" else -volume

    logger.info("S4策略总可下单量{0}，可开量{1}，可平量{2}", trade_strategy['max_volume'], trade_strategy['open_volume'], trade_strategy['close_volume'])
